
component  extends="ModelGlue.gesture.controller.Controller" output="false" beans="core"
{
	public ModelGlue.gesture.controller.Controller function init( required Any modelGlue){
		
		super.init( arguments.modelGlue );
		
		return this;
	}
	
	public ModelGlue.Core.Event function new( required Any event ){
		
		var service = beans.core.getService( 'Blog' );
		var Blog = service.newBlog();
		
		arguments.event.setValue( 'Blog', Blog );
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function save( required Any event ){
		
		var service = beans.core.getService( 'Blog' );
		var Blog = service.new();
		var validator = service.getValidator();
		
		arguments.event.makeEventBean( Blog );
		
		arguments.event.setValue( 'Blog', Blog );
		
		validator.validate( Blog );
			
		if( validator.hasErrors() ){
		
			arguments.event.setValue( 'error', validator.getErrors() );

			arguments.event.setValue( 'errorBox', 'Setting not saved.' );
			
			arguments.event.addResult( 'save.failure' );
		
		}else{
			
				service.saveBlog( Blog );
				
				arguments.event.setValue( 'successBox', 'Setting saved.' );
				
				arguments.event.addResult( 'save.success' );
			
		}
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function get( required Any event ){
		
		var service = beans.core.getService( 'Blog' );
		var Blog = service.new();
		var result = "";
		
		Blog.setIdBlog( 'easyblog' );
		
		result = service.getBlog( Blog );
									
		arguments.event.setValue( 'Blog', result );
		
		return arguments.event;
	}

}
